Controlling operation of a run-time instrumentation facility from a lesser-privileged state

ABSTRACT

Embodiments of the invention relate to enabling and disabling execution of a run-time instrumentation facility. An instruction for execution by the processor in a lesser privileged state is fetched by the processor. It is determined, by the processor, that the run-time instrumentation facility permits execution of the instruction in the lesser-privileged state and that controls associated with the run-time instrumentation facility are valid. The run-time instrumentation facility is disabled based on the instruction being a run-time instrumentation facility off (RIOFF) instruction. The disabling includes updating a bit in a program status word (PSW) of the processor to indicate that run-time instrumentation data should not be captured by the processor. The run-time instrumentation facility is enabled based on the instruction being a run-time instrumentation facility on (RION) instruction. The enabling includes updating the bit in the PSW to indicate that run-time instrumentation data should be captured by the processor.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a continuation of U.S. patent application Ser. No.13/422,546, filed Mar. 16, 2012, the disclosure of which is incorporatedby reference herein in its entirety.

BACKGROUND

The present invention relates generally to processing within a computingenvironment, and more specifically, to controlling operation of arun-time instrumentation facility from a lesser-privileged state.

Computer processors execute transactions using increasingly complexbranch prediction and instruction caching logic. These processes havebeen introduced to increase instruction throughput, and thereforeprocessing performance. The introduction of logic for improvingperformance makes it difficult to predict with certainty how aparticular software application will execute on the computer processor.During the software development process there is often a balance betweenfunctionality and performance. Software is executed at one or morelevels of abstraction from the underlying hardware that is executing thesoftware. When hardware is virtualized, an additional layer ofabstraction is introduced. With the introduction of performanceenhancing logic, and the various layers of abstraction it is difficultto have a thorough understanding of what is actually occurring at thehardware level when a program is executing. Without this information,software developers use more abstract methods, such as executionduration, memory usage, number of threads, etc., for optimizing thesoftware application.

When hardware specific information is available, it is typicallyprovided to a developer after the fact and it is provided in aggregate,at a high level, and/or interspersed with the activity of otherprograms, and the operating system, making it difficult to identifyissues that may be impacting the efficiency and accuracy of the softwareapplication.

SUMMARY

Embodiments include a method for enabling and disabling execution of arun-time instrumentation facility on a processor. An instruction forexecution by the processor in a lesser privileged state is fetched bythe processor. It is determined, by the processor, that the run-timeinstrumentation facility permits execution of the instruction in thelesser-privileged state and that controls associated with the run-timeinstrumentation facility are valid. The run-time instrumentationfacility is disabled based on the instruction being a run-timeinstrumentation facility off (RIOFF) instruction. The disabling includesupdating a bit in a program status word (PSW) of the processor toindicate that run-time instrumentation data should not be captured bythe processor. The run-time instrumentation facility is enabled based onthe instruction being a run-time instrumentation facility on (RION)instruction. The enabling includes updating the bit in the PSW toindicate that run-time instrumentation data should be captured by theprocessor.

Additional features and advantages are realized through the techniquesof the present invention. Other embodiments and aspects of the inventionare described in detail herein and are considered a part of the claimedinvention. For a better understanding of the invention with advantagesand features, refer to the description and to the drawings.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

The subject matter which is regarded as the invention is particularlypointed out and distinctly claimed in the claims at the conclusion ofthe specification. The forgoing and other features, and advantages ofthe invention are apparent from the following detailed description takenin conjunction with the accompanying drawings in which:

FIG. 1A is a diagram depicting an example host computer system in anembodiment;

FIG. 1B is a diagram depicting an example emulation host computer systemin an embodiment;

FIG. 1C is a diagram depicting an example computer system in anembodiment;

FIG. 2 is a diagram depicting an example computer network in anembodiment;

FIG. 3 is a diagram depicting elements of a computer system in anembodiment;

FIGS. 4A-4C depict detailed elements of a computer system in anembodiment;

FIG. 5 depicts a schematic diagram of a system for run-timeinstrumentation of a processor in accordance with an embodiment;

FIG. 6 depicts a portion of a run-time instrumentation control block(RICCB) including controls that are settable by a privileged state in anembodiment;

FIG. 7 depicts a portion of a RICCB control block when thesemi-privileged bit (K) is set to 1 in an embodiment;

FIG. 8 depicts a collection buffer in accordance with an embodiment;

FIG. 9 depicts a reporting group in accordance with an embodiment;

FIG. 10 depicts a process flow for implementing a run-timeinstrumentation facility in accordance with an embodiment;

FIG. 11 depicts a run-time instrumentation off (RIOFF) instruction inaccordance with an embodiment;

FIG. 12 depicts a process flow of an RIOFF instruction in accordancewith an embodiment;

FIG. 13 depicts a run-time instrumentation on (RION) instruction inaccordance with an embodiment;

FIG. 14 depicts a process flow of an RION instruction in accordance withan embodiment; and

FIG. 15 illustrates a computer program product in accordance with anembodiment.

DETAILED DESCRIPTION

A run-time instrumentation facility allows a processor to collecthardware event data into a rolling history buffer, sample the historybuffer, and store data from the history buffer into applicationaccessible storage. It is generally desirable to limit sampling to asubset of the execution trace of an application as there may be elementsin the execution path that may not be of interest. For example, if datacollected by the run-time instrumentation facility will be used toenhance a program that was compiled by a compiler, then data related tothe run-time environment and the operating system services may not beuseful (e.g., because the complier may have no ability to affect therun-time environment or the operating system services). Additionally, bylimiting the range of the execution path that is sampled, the run-timeinstrumentation facility can reduce the cost of having to manage,buffer, and reduce the collected instrumentation data, thus keeping theoverhead of the instrumentation mechanism to a minimum. Embodimentsdescribed here allow the run-time instrumentation to be turned off(disabled) and on (enabled) based on instructions from an application.

As described in embodiments herein, a first instruction, referred to asa run-time instrumentation on (RION) instruction designates a startingpoint for a sub-trace of the execution path to be sampled. Also asdescribed herein, a second instruction, referred to as a run-timeinstrumentation off (RIOFF) instruction designates an ending point ofthe execution path to be sampled. These instructions may be insertedinto an instruction stream at transition points between the compiledcode and the run-time environment. In addition, the RION and RIOFFinstructions may be inserted by the compiler into the instruction streamto focus the sampling mechanism on specific areas of the compiled code.

A bit in a program status word (PSW) is used, in accordance withembodiments, to designate the state of the run-time instrumentationfacility. The bit in the PSW indicates whether the current executionpoint is inside of a sampling interval (i.e., the run-timeinstrumentation facility is turned on and collecting data) or outside ofa sampling interval (i.e., the run-time instrumentation facility isturned off and not collecting data) of the executing trace. As the PSWis saved and restored across context switches, the state of the samplingmechanism is naturally maintained across dispatches of the executingthread.

An embodiment of the present invention is a hardware based run-timeinstrumentation facility for managed run-times. As used herein the term“managed run-time” refers to an environment that encapsulates a stateand manages resources used to execute a program or application (e.g.,Java® virtual machine or “JVM”, operating system, middleware, etc.).Embodiments of the run-time instrumentation facility enable a program tocollect information about program execution, including centralprocessing unit (CPU) data. The collected information allows the managerrun-time environment to acquire insights about the program from whichthe information is collected. Embodiments of the run-timeinstrumentation facility include a hardware facility for collectingsequences of events (e.g., taken branches, register values, etc.) in acollection buffer. The collection buffer (or a subset of the collectionbuffer containing the most recent records) is copied into a programbuffer in the application's address space (for example the address spaceof a JVM) upon a programmable set of sample triggering events such as,but not limited to: a software directive in the form of an instructioninserted into the instruction stream; an interval of executedinstructions are completed, a given elapsed time since the last sampleexpires, and/or a given hardware event such as data or instruction cachemiss is observed.

Dynamic compilers exploit runtime information, such as that collected bythe hardware based run-time instrumentation facility described herein toperform online feedback directed optimizations. For example, informationabout important execution paths, profiled values and preferred branchdirections can be used by a dynamic compiler to perform optimizationsthat specialize or version code, direct in-lining, re-order executionpaths, and straighten branches. Data generated by embodiments describedherein may also be used for other forms of optimization such as datareorganization.

FIG. 1A, depicts the representative components of a host computer system50 in an embodiment. Other arrangements of components may also beemployed in a computer system. The representative host computer system50 comprises one or more processors 1 in communication with main store(computer memory) 2 as well as I/O interfaces to storage devices 11 andnetworks 10 for communicating with other computers or SANs and the like.The processor 1 is compliant with an architecture having an architectedinstruction set and architected functionality. The processor 1 may havedynamic address translation (DAT) 3 for transforming program addresses(virtual addresses) into a real address in memory. A DAT 3 typicallyincludes a translation lookaside buffer (TLB) 7 for caching translationsso that later accesses to the block of computer memory 2 do not requirethe delay of address translation. Typically a cache 9 is employedbetween the computer memory 2 and the processor 1. The cache 9 may behierarchical having a large cache available to more than one CPU andsmaller, faster (lower level) caches between the large cache and eachCPU. In some embodiments, the lower level caches are split to provideseparate low level caches for instruction fetching and data accesses. Inan embodiment, an instruction is fetched from the computer memory 2 byan instruction fetch unit 4 via the cache 9. The instruction is decodedin an instruction decode unit 6 and dispatched (with other instructionsin some embodiments) to instruction execution units 8. Typically severalinstruction execution units 8 are employed, for example an arithmeticexecution unit, a floating point execution unit and a branch instructionexecution unit. The instruction is executed by the instruction executionunit 8, accessing operands from instruction specified registers or thecomputer memory 2 as needed. If an operand is to be accessed (loaded orstored) from the computer memory 2, the load store unit 5 typicallyhandles the access under control of the instruction being executed.Instructions may be executed in hardware circuits or in internalmicrocode (firmware) or by a combination of both.

In FIG. 1B, depicts an emulated host computer system 21 is provided thatemulates a host computer system of a host architecture, such as the hostcomputer system 50 of FIG. 1. In the emulated host computer system 21, ahost processor (CPU) 1 is an emulated host processor (or virtual hostprocessor) 29, and comprises a native processor 27 having a differentnative instruction set architecture than that of the processor 1 of thehost computer system 50. The emulated host computer system 21 has memory22 accessible to the native processor 27. In an embodiment, the memory22 is partitioned into a computer memory 2 portion and an emulationroutines memory 23 portion. The computer memory 2 is available toprograms of the emulated host computer system 21 according to the hostcomputer architecture. The native processor 27 executes nativeinstructions of an architected instruction set of an architecture otherthan that of the emulated processor 29, the native instructions obtainedfrom the emulation routines memory 23, and may access a host instructionfor execution from a program in the computer memory 2 by employing oneor more instruction(s) obtained in a sequence & access/decode routinewhich may decode the host instruction(s) accessed to determine a nativeinstruction execution routine for emulating the function of the hostinstruction accessed. Other facilities that are defined for the hostcomputer system 50 architecture may be emulated by architectedfacilities routines, including such facilities as general purposeregisters, control registers, dynamic address translation andinput/output (I/O) subsystem support and processor cache for example.The emulation routines may also take advantage of function available inthe native processor 27 (such as general registers and dynamictranslation of virtual addresses) to improve performance of theemulation routines. Special hardware and off-load engines may also beprovided to assist the native processor 27 in emulating the function ofthe host computer system 50.

In a mainframe, architected machine instructions are used byprogrammers, usually today “C” programmers often by way of a compilerapplication. These instructions stored in the storage medium may beexecuted natively in a z/Architecture IBM Server, or alternatively inmachines executing other architectures. They can be emulated in theexisting and in future IBM mainframe servers and on other machines ofIBM (e.g. pSeries® Servers and xSeries® Servers). They can be executedin machines running Linux on a wide variety of machines using hardwaremanufactured by IBM®, Intel®, AMD™, Sun Microsystems and others. Besidesexecution on that hardware under a Z/Architecture®, Linux can be used aswell as machines which use emulation by Hercules, UMX, FundamentalSoftware, Inc. (FSI) or Platform Solutions, Inc. (PSI), where generallyexecution is in an emulation mode. In emulation mode, emulation softwareis executed by a native processor to emulate the architecture of anemulated processor.

One or more of the components of the emulated host computer system 21are further described in “IBM® z/Architecture Principles of Operation,”Publication No. SA22-7832-08, 9th Edition, August, 2010 which is herebyincorporated herein by reference in its entirety. IBM is a registeredtrademark of International Business Machines Corporation, Armonk, N.Y.,USA. Other names used herein may be registered trademarks, trademarks orproduct names of International Business Machines Corporation or othercompanies.

The native processor 27 typically executes emulation software stored inthe emulation routines memory 23 comprising either firmware or a nativeoperating system to perform emulation of the emulated processor. Theemulation software is responsible for fetching and executinginstructions of the emulated processor architecture. The emulationsoftware maintains an emulated program counter to keep track ofinstruction boundaries. The emulation software may fetch one or moreemulated machine instructions at a time and convert the one or moreemulated machine instructions to a corresponding group of native machineinstructions for execution by the native processor 27. These convertedinstructions may be cached such that a faster conversion can beaccomplished. The emulation software maintains the architecture rules ofthe emulated processor architecture so as to assure operating systemsand applications written for the emulated processor operate correctly.Furthermore the emulation software provides resources identified by theemulated processor architecture including, but not limited to controlregisters, general purpose registers, floating point registers, dynamicaddress translation function including segment tables and page tablesfor example, interrupt mechanisms, context switch mechanisms, time ofday (TOD) clocks and architected interfaces to I/O subsystems such thatan operating system or an application program designed to run on theemulated processor 29, can be run on the native processor 27 having theemulation software.

A specific instruction being emulated is decoded, and a subroutinecalled to perform the function of the individual instruction. Anemulation software function emulating a function of an emulatedprocessor 29 is implemented, for example, in a “C” subroutine or driver,or some other method of providing a driver for the specific hardware aswill be within the skill of those in the art after understanding thedescription of the preferred embodiment.

In an embodiment, the invention may be practiced by software (sometimesreferred to licensed internal code, firmware, micro-code, milli-code,pico-code and the like, any of which would be consistent with thepresent invention). Referring to FIG. 1A, software program code whichembodies the present invention is accessed by the processor also knownas a CPU (Central Processing Unit) 1 of the host computer system 50 fromthe storage device 11 such as a long-term storage media, a CD-ROM drive,tape drive or hard drive. The software program code may be embodied onany of a variety of known media for use with a data processing system,such as a diskette, hard drive, or CD-ROM. The code may be distributedon such media, or may be distributed to users from the computer memory 2or storage of one computer system over a network 10 to other computersystems for use by users of such other systems.

Alternatively, the program code may be embodied in the computer memory2, and accessed by the processor 1 using a processor bus (not shown).Such program code includes an operating system which controls thefunction and interaction of the various computer components and one ormore application programs. Program code is normally paged from a densemedia such as the storage device 11 to computer memory 2 where it isavailable for processing by the processor 1. The techniques and methodsfor embodying software program code in memory, on physical media, and/ordistributing software code via networks are well known and will not befurther discussed herein. Program code, when created and stored on atangible medium (including but not limited to electronic memory modules(RAM), flash memory, compact discs (CDs), DVDs, Magnetic Tape and thelike is often referred to as a “computer program product.” The computerprogram product medium is typically readable by a processing circuitpreferably in a computer system for execution by the processing circuit.

FIG. 1C illustrates a representative workstation or server hardwaresystem in which the present invention may be practiced. The system 100of FIG. 1C comprises a representative base computer system 101, such asa personal computer, a workstation or a server, including optionalperipheral devices. The base computer system 101 includes one or moreprocessors 106 and a bus (not shown) employed to connect and enablecommunication between the one or more processors 106 and the othercomponents of the base computer system 101 in accordance with knowntechniques. The bus connects the processor 106 to memory 105 andlong-term storage 107 which may include a hard drive (including any ofmagnetic media, CD, DVD and Flash Memory for example) or a tape drivefor example. The base computer system 101 may also include a userinterface adapter, which connects the one or more processors 106 via thebus to one or more interface devices, such as a keyboard 104, a mouse103, a printer/scanner 110 and/or other interface devices, which may beany user interface device, such as a touch sensitive screen, digitizedentry pad, etc. The bus also connects the one or more processors to adisplay device 102, such as an LCD screen or monitor via a displayadapter.

The base computer system 101 may communicate with other computers ornetworks of computers by way of a network adapter capable ofcommunicating 108 with a network 109. Example network adapters arecommunications channels, token ring, Ethernet or modems. Alternatively,the base computer system 101 may communicate using a wireless interface,such as a cellular digital packet data (CDPD) card. The base computersystem 101 may be associated with such other computers in a local areanetwork (LAN) or a wide area network (WAN), or the base computer system101 may be a client in a client/server arrangement with anothercomputer, etc.

FIG. 2 illustrates a data processing network 200 in which the presentinvention may be practiced. The data processing network 200 may includea plurality of individual networks, such as a wireless network and awired network, each of which may include a plurality of individualworkstations 201, 202, 203, 204 and or the base computer system 101 ofFIG. 1C. Additionally, as those skilled in the art will appreciate, oneor more LANs may be included, where a LAN may comprise a plurality ofintelligent workstations coupled to a host processor.

Programming code 111 may be embodied in the memory 105, and accessed bythe processor 106 using the processor bus. Such programming codeincludes an operating system which controls the function and interactionof the various computer components and one or more application programs112. Program code is normally paged from long-term storage 107 tohigh-speed memory 105 where it is available for processing by theprocessor 106. The techniques and methods for embodying softwareprogramming code in memory, on physical media, and/or distributingsoftware code via networks are well known and will not be furtherdiscussed herein. Program code, when created and stored on a tangiblemedium (including but not limited to electronic memory modules (RAM),flash memory, Compact Discs (CDs), DVDs, Magnetic Tape and the like isoften referred to as a “computer program product”. The computer programproduct medium is typically readable by a processing circuit preferablyin a computer system for execution by the processing circuit.

The cache that is most readily available to the processor (normallyfaster and smaller than other caches of the processor) is the lowest (L1or level one) cache and main store (main memory) is the highest levelcache (L3 if there are 3 levels). The lowest level cache is oftendivided into an instruction cache (I-Cache) holding machine instructionsto be executed and a data cache (D-Cache) holding data operands.

Still referring to FIG. 2, the networks may also include mainframecomputers or servers, such as a gateway computer (client server) 206 orapplication server (remote server) 208 which may access a datarepository and may also be accessed directly from a workstation 205. Agateway computer 206 serves as a point of entry into each network 207. Agateway is needed when connecting one networking protocol to another.The gateway computer 206 may be preferably coupled to another network(the Internet 207 for example) by means of a communications link. Thegateway computer 206 may also be directly coupled to the one or moreworkstations 101, 201, 202, 203, and 204 using a communications link.The gateway computer may be implemented utilizing an IBM eServer™zSeries® z9® Server available from International Business MachinesCorporation.

In an embodiment, software programming code which embodies the presentinvention is accessed by the processor 106 of the base computer system101 from long-term storage media, such as the long-term storage 107 ofFIG. 1C. The software programming code may be embodied on any of avariety of known media for use with a data processing system, such as adiskette, hard drive, or CD-ROM. The code may be distributed on suchmedia, or may be distributed to users 210 and 211 from the memory orstorage of one computer system over a network to other computer systemsfor use by users of such other systems.

Referring to FIG. 3, an exemplary processor embodiment is depicted forprocessor 106. One or more levels of cache 303 are employed to buffermemory blocks in order to improve the performance of the processor 106.The cache 303 is a high speed buffer holding cache lines of memory datathat are likely to be used. Typical cache lines are 64, 128 or 256 bytesof memory data. In an embodiment, separate caches are employed forcaching instructions than for caching data. Cache coherence(synchronization of copies of lines in memory and the caches) is oftenprovided by various “snoop” algorithms well known in the art. Mainstorage, such as memory 105 of a processor system is often referred toas a cache. In a processor system having 4 levels of cache 303 memory105 is sometimes referred to as the level 5 (L5) cache since it istypically faster and only holds a portion of the non-volatile storage(DASD, Tape etc) that is available to a computer system. Memory 105“caches” pages of data paged in and out of the memory 105 by theoperating system.

A program counter (instruction counter) 311 keeps track of the addressof the current instruction to be executed. A program counter in az/Architecture processor is 64 bits and may be truncated to 31 or 24bits to support prior addressing limits. A program counter is typicallyembodied in a program status word (PSW) of a computer such that itpersists during context switching. Thus, a program in progress, having aprogram counter value, may be interrupted by, for example, the operatingsystem (i.e., the current context switches from the program environmentto the operating system environment). The PSW of the program maintainsthe program counter value while the program is not active, and theprogram counter (in the PSW) of the operating system is used while theoperating system is executing. In an embodiment, the program counter isincremented by an amount equal to the number of bytes of the currentinstruction. Reduced Instruction Set Computing (RISC) instructions aretypically fixed length while Complex Instruction Set Computing (CISC)instructions are typically variable length. Instructions of the IBMz/Architecture are CISC instructions having a length of 2, 4 or 6 bytes.The program counter 311 is modified by either a context switch operationor a branch taken operation of a branch instruction for example. In acontext switch operation, the current program counter value is saved inthe PSW along with other state information about the program beingexecuted (such as condition codes), and a new program counter value isloaded pointing to an instruction of a new program module to beexecuted. A branch taken operation is performed in order to permit theprogram to make decisions or loop within the program by loading theresult of the branch instruction into the program counter 311.

In an embodiment, an instruction fetch unit 305 is employed to fetchinstructions on behalf of the processor 106. The instruction fetch unit305 either fetches the “next sequential instructions,” the targetinstructions of branch taken instructions, or the first instructions ofa program following a context switch. In an embodiment, the instructionfetch unit 305 employs prefetch techniques to speculatively prefetchinstructions based on the likelihood that the prefetched instructionsmight be used. For example, the instruction fetch unit 305 may fetch 16bytes of instructions that include the next sequential instruction andadditional bytes of further sequential instructions.

The fetched instructions are then executed by the processor 106. In anembodiment, the fetched instruction(s) are passed to a decode/dispatchunit 306 of the instruction fetch unit 305. The decode/dispatch unit 306decodes the instruction(s) and forwards information about the decodedinstruction(s) to appropriate execution units 307, 308, and/or 310. Anexecution unit 307 receives information about decoded arithmeticinstructions from the instruction fetch unit 305 and will performarithmetic operations on operands according to the operation code(opcode) of the instruction. Operands are provided to the execution unit307 either from the memory 105, architected registers 309, or from animmediate field of the instruction being executed. Results of theexecution, when stored, are stored either in memory 105, architectedregisters 309 or in other machine hardware (such as control registers,PSW registers and the like).

A processor 106 typically has one or more execution units 307, 308, and310 for executing the function of the instruction. Referring to FIG. 4A,an execution unit 307 may communicate with the architected registers309, the decode/dispatch unit 306, the load/store unit 310 and otherprocessor units 401 by way of interfacing logic 407. The execution unit307 may employ several register circuits 403, 404, and 405 to holdinformation that the arithmetic logic unit (ALU) 402 will operate on.The ALU 402 performs arithmetic operations such as add, subtract,multiply and divide as well as logical function such as and, or andexclusive-or (xor), rotate and shift. In an embodiment, the ALU supportsspecialized operations that are design dependent. Other circuits mayprovide other architected facilities 408 including condition codes andrecovery support logic for example. Typically the result of an ALUoperation is held in an output register circuit 406 which can forwardthe result to a variety of other processing functions. In otherembodiments, there are many arrangements of processor units, the presentdescription is only intended to provide a representative understandingof one embodiment.

An ADD instruction for example would be executed in an execution unit307 having arithmetic and logical functionality while a floating pointinstruction for example would be executed in a floating point executionunit (not shown) having specialized floating point capability.Preferably, an execution unit operates on operands identified by aninstruction by performing an opcode defined function on the operands.For example, an ADD instruction may be executed by an execution unit 307on operands found in two architected registers 309 identified byregister fields of the instruction.

The execution unit 307 performs the arithmetic addition on two operandsand stores the result in a third operand where the third operand may bea third register or one of the two source registers. The execution unit307 preferably utilizes an arithmetic logic unit (ALU) 402 that iscapable of performing a variety of logical functions such as shift,rotate, and, or and XOR as well as a variety of algebraic functionsincluding any of add, subtract, multiply, divide. Some ALUs 402 aredesigned for scalar operations and some for floating point. Inembodiments, data may be big endian (where the least significant byte isat the highest byte address) or little endian (where the leastsignificant byte is at the lowest byte address) depending onarchitecture. The IBM z/Architecture is big endian. Signed fields may besign and magnitude, 1's complement or 2's complement depending onarchitecture. A 2's complement number is advantageous in that the ALUdoes not need to design a subtract capability since either a negativevalue or a positive value in 2's complement requires only and additionwithin the ALU. Numbers are commonly described in shorthand, where a 12bit field defines an address of a 4,096 byte block and is commonlydescribed as a 4 Kbyte (Kilo-byte) block for example.

Referring to FIG. 4B, Branch instruction information for executing abranch instruction is typically sent to a branch unit 308 which employsa branch prediction algorithm such as a branch history table 432 topredict the outcome of the branch before other conditional operationsare complete. The target of the current branch instruction will befetched and speculatively executed before the conditional operations arecomplete. When the conditional operations are completed thespeculatively executed branch instructions are either completed ordiscarded based on the conditions of the conditional operation and thespeculated outcome. A typical branch instruction may test conditioncodes and branch to a target address if the condition codes meet thebranch requirement of the branch instruction, a target address may becalculated based on several numbers including ones found in registerfields or an immediate field of the instruction for example. In anembodiment, the branch unit 308 may employ an ALU 426 having a pluralityof input register circuits 427, 428, and 429 and an output registercircuit 430. The branch unit 308 may communicate with general registers,decode/dispatch unit 306 or other circuits 425 for example.

The execution of a group of instructions may be interrupted for avariety of reasons including a context switch initiated by an operatingsystem, a program exception or error causing a context switch, an I/Ointerruption signal causing a context switch or multi-threading activityof a plurality of programs (in a multi-threaded environment) forexample. In an embodiment, a context switch action saves stateinformation about a currently executing program and then loads stateinformation about another program being invoked. State information maybe saved in hardware registers or in memory for example. Stateinformation includes a program counter value pointing to a nextinstruction to be executed, condition codes, memory translationinformation and architected register content. A context switch activitymay be exercised by hardware circuits, application programs, operatingsystem programs or firmware code (microcode, pico-code or licensedinternal code (LIC) alone or in combination.

A processor accesses operands according to instruction defined methods.The instruction may provide an immediate operand using the value of aportion of the instruction, may provide one or more register fieldsexplicitly pointing to either general purpose registers or specialpurpose registers (floating point registers for example). Theinstruction may utilize implied registers identified by an opcode fieldas operands. The instruction may utilize memory locations for operands.A memory location of an operand may be provided by a register, animmediate field, or a combination of registers and immediate field asexemplified by the z/Architecture long displacement facility wherein theinstruction defines a base register, an index register and an immediatefield (displacement field) that are added together to provide theaddress of the operand in memory. Location herein implies a location inmain memory (main storage) unless otherwise indicated.

Referring to FIG. 4C, a processor accesses storage using a load/storeunit 310. The load/store unit 310 may perform a load operation byobtaining the address of the target operand in memory through thecache/memory interface and loading the operand in an architectedregister 309 or another memory location, or may perform a storeoperation by obtaining the address of the target operand in memory andstoring data obtained from an architected register 309 or another memorylocation in the target operand location in memory. The load/store unit310 may be speculative and may access memory in a sequence that isout-of-order relative to the instruction sequence; however theload/store unit 310 maintains the appearance to programs thatinstructions were executed in order. A load/store unit 310 maycommunicate with architected registers 309, decode/dispatch unit 306,cache/memory interface or other elements 455 and comprises variousregister circuits, ALUs 458 and control logic 463 to calculate storageaddresses and to provide pipeline sequencing to keep operationsin-order. Some operations may be out of order but the load/store unitprovides functionality to make the out of order operations appear to theprogram as having been performed in order as is well known in the art.

Preferably addresses that an application program “sees” are oftenreferred to as virtual addresses. Virtual addresses are sometimesreferred to as “logical addresses” and “effective addresses.” Thesevirtual addresses are virtual in that they are redirected to physicalmemory location by one of a variety of DAT technologies such as the DAT312 of FIG. 3, including, but not limited to prefixing a virtual addresswith an offset value, translating the virtual address via one or moretranslation tables, the translation tables including at least a segmenttable and a page table alone or in combination, preferably, the segmenttable having an entry pointing to the page table. In z/Architecture, ahierarchy of translations is provided including a region first table, aregion second table, a region third table, a segment table and anoptional page table. The performance of the address translation is oftenimproved by utilizing a translation look-aside buffer (TLB) whichcomprises entries mapping a virtual address to an associated physicalmemory location. The entries are created when DAT 312 translates avirtual address using the translation tables. Subsequent use of thevirtual address can then utilize the entry of the fast TLB rather thanthe slow sequential translation table accesses. The TLB content may bemanaged by a variety of replacement algorithms including least recentlyused (LRU).

In the case where the processor 106 is a processor of a multi-processorsystem, each processor has responsibility to keep shared resources suchas I/O, caches, TLBs and Memory interlocked for coherency. In anembodiment, “snoop” technologies will be utilized in maintaining cachecoherency. In a snoop environment, each cache line may be marked asbeing in any one of a shared state, an exclusive state, a changed state,an invalid state and the like in order to facilitate sharing.

The I/O units 304 of FIG. 3 provide the processor 106 with means forattaching to peripheral devices including tape, disc, printers,displays, and networks for example. The I/O units 304 are oftenpresented to the computer program by software drivers. In mainframessuch as the z/Series from IBM, channel adapters and open system adaptersare I/O units of the mainframe that provide the communications betweenthe operating system and peripheral devices.

Instrumentation data is data related to the operations of the processor106. In an embodiment, access to instrumentation data and other systemlevel metrics may be restricted, or unavailable. A computer processoroperates under a privileged state (or supervisor state), and alesser-privileged state (or problem state). In the privileged state, aprogram may have access to all system resources via privilegedoperations (e.g., access to all control registers and the supervisormemory space). The privileged state is also referred to as privilegedmode or supervisor mode. An operating system executing on the computerprocessor may be operating in the privileged state. Thelesser-privileged state is a non-privileged state where access to systemresources is limited. For example, application programs running inlesser-privileged state may have limited or no access to controlregisters and may access only user memory space assigned to theapplication program by the operating system. The lesser-privileged stateis typically assigned to application programs executed under control ofan operating system, and no privileged operations can be performed inthe lesser-privileged state. The lesser-privileged state is also knownas a problem state, problem mode or user mode.

One such restricted resource that is not write accessible to a programexecuting in the lesser-privileged state is the program status word(PSW). The PSW may comprise a program counter of the next instruction tobe executed, a condition code field usable by branch instructions, aninstrumentation control field for indicating whether instrumentation isenabled or disabled, and other information used to control instructionsequencing and to determine the state of the computer processorincluding the privilege state assigned to the program. In amultithreaded processing environment, multiple programs share, or timeslice, the available computer processor capacity. Each of the programshas context information including an associated PSW, an origin addressof an address translation table for accessing main storage assigned tothe program, a set of general purpose register current values, controlregisters, floating point registers, etc. The currently active, orcontrolling PSW, is called the current PSW. It governs the programcurrently being executed. The computer processor has an interruptioncapability, which permits the computer processor to context switchrapidly to another program in response to exception conditions andexternal stimuli. When an interruption occurs, the computer processorplaces the current PSW in an assigned storage location, called theold-PSW location, for the particular class of interruption. The computerprocessor fetches a new PSW from a second assigned storage location.This new context determines the next program to be executed. In anembodiment, these storage locations are located in a memory locationaccessible to the computer processor. When the computer processor hasfinished processing the interruption, the program handling theinterruption may reload the old context including the old PSW, making itagain the current PSW, so that the interrupted program can continue.

The fields of the PSW may be referenced either explicitly (e.g., wheninstruction execution reads part of the PSW bits), or implicitly (e.g.,in instructions fetching, operand fetching, address generationcalculations, address generation sources, etc.). The explicit referenceis generally performed at execution time, whereas the implicit referenceis generally performed at different stages of the pipeline duringinstruction execution (i.e., instruction fetch, instruction decode,execution time and completion time). Individual fields in the PSW may bereferenced or updated independently of each other.

In an embodiment, by manipulating the context, an operating systemcontrols computer processing resources, including enablingrun-time-instrumentation by the computer processor. Therun-time-instrumentation may be enabled or disabled during the executionof the operating system, as well as by any software applicationsexecuted by the operating system. The enabled/disabled state ofrun-time-instrumentation is saved as context information in the PSWassociated with a program.

A run-time-instrumentation (RI) facility may be incorporated on modelsimplementing z/Architecture. When the RI facility is installed andenabled, data is collected during program execution into one or morecollection buffers within the CPU and then reported to a program buffer.Each unit of information stored is called a reporting group. Thecontents of a reporting group consist of multiple records whose contentsrepresent events recognized by the CPU during program execution.

When the run-time-instrumentation facility is installed in aconfiguration, a PSW field (RI bit) enables run-time-instrumentation.Validity of the run-time-instrumentation controls determines thecapability of turning on the RI bit, but when RI is one, the CPUcontrols are valid and run-time-instrumentation is enabled. Therun-time-instrumentation facility may include the followinginstructions: load run-time-instrumentation controls, modifyrun-time-instrumentation controls, run-time-instrumentation emit,run-time-instrumentation next, run-time-instrumentation off,run-time-instrumentation on, store run-time-instrumentation controls,and test run-time-instrumentation controls.

The load run-time-instrumentation controls (LRIC) instructioninitializes the run-time-instrumentation controls that governrun-time-instrumentation. The modify run-time-instrumentation controls(MRIC) instruction modifies all or a subset of therun-time-instrumentation controls originally established by LRIC. Therun-time-instrumentation emit (RIEMIT) instruction collects the value ofa general register by storing it into a collection buffer. Therun-time-instrumentation next (RINEXT) instruction performs directedsampling of the next, sequential instruction (NSI) after RINEXT. Therun-time-instrumentation off (RIOFF) instruction disablesrun-time-instrumentation. The run-time-instrumentation on (RION)instruction enables run-time-instrumentation. The storerun-time-instrumentation controls (STRIC) instruction places the currentvalues of the run-time-instrumentation controls into a specified storagelocation. The test run-time-instrumentation controls (TRIC) instructionexamines the run-time-instrumentation controls. If valid, the state of acontrols-altered indicator is set.

The run-time-instrumentation facility includes the ability for making ameasurement-alert external interruption pending. Some of the informationcollected by run-time-instrumentation and reported to a program bufferis model-dependent and thus not defined. Samples and data provided bythe run-time-instrumentation facility are intended for statisticalestimation of performance characteristics, are substantially accurate,and may not be repeatable. For example, regardless of sampling mode, itis unpredictable if a sample instruction that caused an exception or isassociated with certain system internal activities would result in thestore of a reporting group and, if stored, whether the model-dependentdata included in run-time-instrumentation data is affected.

A collection buffer is used to capture a set of records whose contentsreport on events recognized by the processor during program execution.Examples are: execution of one or more taken branches,transactional-execution abort events, instruction-fetch cache misses,data fetch or store cache misses, and an operand of the RIEMITinstruction. Execution of the RIEMIT instruction collects the value of ageneral register by storing it into the collection buffer. Additionaldata can be collected and/or stored in other buffers, such as aninstruction-data buffer.

Reporting is subject to reporting controls. When a sample instruction isidentified, each reporting control enables the checking of acorresponding condition. If a corresponding condition exists, areporting group is formed and stored. A reporting group is not storedwhen no reporting control is enabled or the corresponding condition doesnot exist for an enabled reporting control. Data reported about a sampleinstruction may be acquired from the instruction-data buffer and othermodel-dependent sources, and then used to create the contents of one ormore records of the reporting group, one such record being aninstruction record.

Record types that may be captured in the reporting group store include:filler, extra, begin, timestamp, instruction, emit, TX abort, call,return, and transfer. A filler record is used in a reporting group whenthe number of valid records in the collection buffer is not sufficientto fill a reporting group of the current reporting-group size. An extrarecord may be used in the extra section of a reporting group. A beginrecord is the first record of the first reporting group. A timestamprecord is stored as record 0 of every reporting group other than thefirst reporting group. An instruction record is created when a reportinggroup is stored for a sample instruction as the last record of thereporting group. An emit record is created by successful execution ofRIEMIT. A transaction-execution (TX) mode abort record is created byeither an implicit abort or by execution of a transaction abortinstruction. A call record is created by execution of a branchinstruction which is categorized as a call-type branch instruction. Areturn record is created by execution of a return-type branchinstruction which is categorized as a return instruction. A transferrecord is created by execution of a branch instruction which meetscertain condition code criteria.

FIG. 5 depicts a schematic diagram of a system forrun-time-instrumentation of a processor that may be implemented in anembodiment. In an embodiment, the system 500 includes a centralprocessing unit (CPU) such as the processor 106 of FIG. 1. In anembodiment, the processor 106 is a single processor. In an alternateembodiment, the processor 106 is a single processing core of amulti-core processor. In an embodiment, the processor 106 is capable ofoperating at varying speeds.

In an embodiment, the processor 106 further includes a register 510. Theregister 510 is a hardware register capable of storing words of data foruse by the processor 106. The register 510 includes one or more latchesfor storing bits of data that are accessible by the processor 106. Theregister 510 may include general purpose registers and control registersfor example. The processor 106 additionally includes an instrumentationmodule 506 that is in communication with the register 510. Theinstrumentation module 506 is a processing circuit that controls theinstrumentation of the processor 106. The instrumentation module 506 isconfigured to collect instrumentation data, such as the execution pathof one or more taken branches, transactional execution abort events,various runtime operands, timestamp information, etc. directly from theprocessor 106. The instrumentation module 506 collects theinstrumentation data from the processor 106, and stores theinstrumentation data in a collection buffer 508. In an embodiment, thecollection buffer 508 is a circular buffer that collects data receivedfrom the instrumentation module 506, and when the circular buffer isfilled it overwrites the oldest data with new data.

The processor 106 executes one or more operating systems 516 and one ormore applications 518. The one or more operating systems 516 and one ormore applications 518 are stored in a storage 520, such as a hard drive,CD/ROM, flash memory, etc. and are loaded into a main memory 514 in aruntime memory 504 area reserved for storing one or more active piecesof the currently executing operating system and/or application, calledpages, which are loaded from the storage 520 into runtime memory 504 asneeded. In an embodiment, each of the operating systems execute as avirtual machine managed by a hypervisor (not shown) and executed by theprocessor 106.

In an embodiment the processor 106 loads a PSW 512 in the register 510from PSW data 512 in the main memory 514 for the currently executingoperating system or application from the main memory 514 and sets one ormore processor settings in, for example, the register 510. In anembodiment, the PSW in the register 510, includes one or more bits forenabling and controlling the instrumentation module 506.

The one or more applications 518 include software applications compiledto execute on a specific operating system, interpreted code executing onan interpreter (e.g., Java), or operating system support threads (e.g.,process management, daemons, etc.). Each of the one or more operatingsystems 516 and or the one or more applications 518 may execute aninstruction to trigger the instrumentation module 506 to start, or tostop, the collecting instrumentation data.

In an embodiment, one of the one or more applications 518 executes aninstruction that has been determined to be a sample instruction, therebycreating a sample point at the completion of execution of the sampleinstruction and that then causes the instrumentation module 506 to movethe application's collected data from the collection buffer 508, to aprogram buffer 522 in main memory 514 that is accessible to theapplication. The main memory 514 may be any addressable memory known inthe art. In an embodiment, the main memory 514 may include a fast-accessbuffer storage, sometimes called a cache. Each CPU may have anassociated cache. In an additional embodiment, the main memory 514 isdynamic random access memory (DRAM). In a yet another embodiment, themain memory is a storage device, such as a computer hard drive, or flashmemory accessible by an application.

To configure run-time instrumentation controls, the processor 106supports a load run-time instrumentation controls (LRIC) instruction.Beyond the specific LRIC fields described further herein, it will beunderstood that additional fields can be defined to support otherfunctionality. The LRIC instruction can be used to load and initiallyconfigure run-time instrumentation and is supported by instrumentationmodule 506 of FIG. 5. In an embodiment, the instrumentation module 506,also referred to as run-time instrumentation module 506, implementsrun-time-instrumentation controls and reporting controls. A currentstate of run-time instrumentation controls can be stored from register510 of FIG. 5 into main memory 514 using the store run-time controls(STRIC) instruction. The definition of various fields of a control blockloadable as an operand of the LRIC instruction is also used herein torefer to the state of corresponding values of therun-time-instrumentation controls.

FIG. 6 depicts a portion of a run-time-instrumentation controls controlblock (RICCB) including controls that are settable by a privileged statein an embodiment. The control block portion 600 may include additionalvalues other than those described in reference to FIG. 6. Modificationto the control block portion 600 may be performed by an LRICinstruction.

The control block portion includes a validity bit 602 (V bit). Thevalidity bit 602 indicates the validity of the set ofrun-time-instrumentation controls in the processor, as they werepreviously set by an LRIC instruction.

The control block also includes an S bit 604, which is used to determineif the lesser-privileged state program is allowed to execute an MRICinstruction. The K bit 606 indicates if the lesser-privileged stateprogram is permitted to execute in a semi-privileged state with regardto the run-time-instrumentation controls, such as the origin address,and the limit address of the run-time-instrumentation controls. The Hbit 608 determines whether the address controls (i.e., the originaddress, limit address, and current address) refer to a primary virtualaddress space or a home virtual address space. The 0 bit 610 is ignoredand treated as a 0.

A lesser-privileged state sample reporting control bit 612 (Ps bit) isused in conjunction with lesser-privileged state programs. When in thelesser-privileged state and the Ps bit 612 in therun-time-instrumentation controls is zero, the reporting controls of therun-time-instrumentation controls are ignored whenrun-time-instrumentation is enabled, and thus do not cause a reportinggroup to be stored. When in the lesser-privileged state and the Ps bit612 in the run-time-instrumentation controls is one, the reportingcontrols are checked and used according to their defined function.

A supervisor-state sample reporting control bit 614 (Qs bit) is used inconjunction with supervisor-state programs. When in the supervisor stateand the Qs bit 614 in the run-time-instrumentation controls is zero, thereporting controls of the run-time-instrumentation controls are ignoredwhen run-time-instrumentation is enabled, and thus do not cause areporting group to be stored. When in the supervisor state and the Qsbit 614 in the run-time-instrumentation controls is one, the reportingcontrols are checked and used according to their defined function.

The lesser-privileged state collection buffer control bit 616 (Pc bit)controls updates to the collection buffer 508 of FIG. 5. When inlesser-privileged state and the Pc bit 616 in therun-time-instrumentation controls is zero, collection buffer controls ofthe run-time-instrumentation controls are ignored whenrun-time-instrumentation is enabled and updates of the collection buffer508 are prevented. When in the lesser-privileged state and the Pc bit616 in the run-time-instrumentation controls is one, the collectionbuffer controls are checked and used according to their definedfunction.

The supervisor-state collection buffer control bit 618 (Qc bit) controlsupdates to the collection buffer 508. When in supervisor state and theQc bit 618 in the run-time-instrumentation controls is zero, collectionbuffer controls of the run-time-instrumentation controls are ignoredwhen run-time-instrumentation is enabled and the updates to thecollection buffer 508 are prevented. When in supervisor state and the Qcbit 618 in the run-time-instrumentation controls is one, the indicatedcollection-buffer controls are checked and used according to theirdefined function.

The G bit 620 is the pending control of arun-time-instrumentation-halted interruption, also called a haltedinterruption. When the G bit 620 is zero, a halted interruption is notpending. When the G bit 602 is one, a halted interruption is pending.When the first reporting group in a program buffer 522 is written, the Gbit 620 is set to zero. That is, when run-time-instrumentationprogram-buffer origin address (ROA) 702 equals arun-time-instrumentation program buffer current address (RCA) 706 ofFIG. 7, the G bit 620 is set to zero. When an attempt to store otherthan the first reporting group in program buffer 522 is made, the G bit620 is set to zero if the run-time-instrumentation-halted condition doesnot exist, and the reporting group is stored. When an attempt to storeother than the first reporting group in program buffer 522 is made, theG bit 620 is set to one if the run-time-instrumentation-halted conditiondoes exist, and the reporting group is not stored.

The U bit 622 is the enablement control for a buffer-full interruptionand a halted interruption. When U bit 622 is zero, generation of aninterruption request is disabled and, if pending, remains pending.

The L bit 624 is the pending control of a buffer-full interruption. WhenL bit 624 is zero, a buffer-full interruption is not pending. When L bit624 is one, a buffer-full interruption is pending.

The key field 626 is a 4-bit unsigned integer whose value is used as astorage-protect key for the store of a reporting group. A store of areporting group is permitted only when the storage key matches theaccess key associated with the request for storage access, and a fetchis permitted when the storage key matches the access key or when afetch-protection bit of the storage key is zero. The keys match when thefour access control bits of the storage key are equal to the access key,or when the access key is zero.

FIG. 7 depicts a portion of an RICCB control block when MRIC ispermitted to execute in semi-privileged mode (i.e., K bit is one). Thecontrol block 700 can also be an operand of an LRIC instruction forinitialization of run-time-instrumentation controls. The control block700 may include additional values other than those described inreference to FIG. 7. In an embodiment, sections of the MRIC instructionoperand that are not otherwise designated are inaccessible by alesser-privileged state program. When the semi-privileged mode ispermitted, a run-time-instrumentation program-buffer origin address(ROA) 702 and a run-time-instrumentation program-buffer limit address(RLA) 704 are set with the MRIC instruction by the lesser-privilegedstate program. The ROA 702 is the location of the first byte of theprogram buffer 522 of FIG. 5. The RLA 704 indicates the location of thelast byte of the program buffer 522.

In an embodiment, a run-time-instrumentation program buffer currentaddress (RCA) 706 may be updated by the MRIC instruction. The RCA 706 isthe location in the program buffer 522 of a next reporting group to bestored. The RCA 706 examines the reporting group size field 744 (RGSfield) and affects the number of significant bit positions used to formthe address of the program buffer 522. The 64-bit RCA 706 is word 0, bitpositions 0 through 26-RGS of word 1, and RGS+5 binary zeros appended onthe right. This is the starting location in the program buffer 522 ofFIG. 5 of a subsequent reporting group that will be stored in theprogram buffer 522. The reporting group is a unit of information that iscreated by the instrumentation module 506, and subsequently stored inthe program buffer 522. In an embodiment, when the RGS field 744specified by the RCA 706 is not equal to the run-time-instrumentationcontrol's current reporting group size (i.e., the RCA 706 would changethe RGS field 744) then the RCA 706 is set to the ROA 702.

A remaining sample interval count field 742 (RSIC field) may be updatedby the lesser-privileged program using the MRIC instruction. The RSICfield 742 includes a 64-bit unsigned integer that indicates a remainingsample interval count. When the value of the RSIC field 742 in therun-time-instrumentation controls is zero or equal to the value in ascaling factor field 740 (SF field), and run-time-instrumentation isenabled, then the next sample interval is a full interval based on thesampling mode 708 (M) and SF field 740 values. When RSIC field 742 isnonzero and less than the SF field 740 and run-time-instrumentation isenabled, the next sample interval is a partial interval. When the RSICfield 742 is nonzero and greater than the SF field 740 value andrun-time-instrumentation is enabled, the next sample interval is anextended interval. When an extended interval expires, the next intervalis based on the SF field 740 value. When the RSIC field 742 is set to anonzero value, it is subject to the same model-dependent maximum limitto which the SF field 740 is also subject. When the original value ofthe RSIC field 742 is zero, the sampling mode will dictate whether theRSIC field 742 is set to the value in the SF field 740 during executionof LRIC and MRIC instructions, or whether it continues to show as zerountil run-time-instrumentation is enabled.

The SF field 740 contains a 64-bit unsigned integer whose value is ascaling factor count of units. The dimension of the units is determinedfrom the mode field 708 (M field). When the value in the RSIC field 742is zero, the SF field 740 provides an initial value of the RSIC field742 that is decremented to zero at which point the current instructionis recognized as a sample instruction, and the interval count isrefreshed from the SF field 740 value. A valid value of the SF field 740is in the range one to 2⁶⁴−1. If zero is specified, a value of one isassumed. However, each model may have both a minimum and a maximum valueof the SF field 740. The minimum and maximum values may also bedifferent based on the mode field 708. If a value less than the minimumis specified, the model-dependent minimum value is loaded. If a valuegreater than the maximum value is specified, the model-dependent maximumvalue is loaded.

The DC control field 736 is a 4-bit unsigned integer whose valuedesignates a cache-latency level associated with a data fetch or storecache miss. That is, the sample instruction encountered a data accesscache miss. Unless prohibited by another run-time-instrumentationcontrol, an attempt is made to store a reporting group representing thesample instruction whose data access recognized a miss at acache-latency level numerically greater than or equal to the leveldesignated by the value of the DC control field 736. The cache structureand cache-latency level for data access is model dependent. For aninstruction with multiple or long operands, it is model dependent which,if any, operand access is used for reporting control. Model-dependentbehavior may ignore the value of the DC control field 736 and thus notuse it as a reason to store a reporting group.

The IC field 734 is a 4-bit unsigned integer whose value designates acache-latency level associated with an instruction-fetch cache miss.That is, the fetch of the sample instruction encountered aninstruction-fetch cache miss. For both the IC field 734 and DC controlfield 736, a cache-latency level is an abstraction of how far a certaincache level access is from the observing processor. The latency leveldepends on the combination of the amount of nested cache levels betweenthe processor and main storage, and how such cache levels are sharedamong multiple processors. A larger latency level generally correspondsto a more time-consuming access. Values in the IC field 734 and DCcontrol field 736 may be thought of as zero-origin identification of acache-latency level. For example, a value of zero corresponds to an L1cache (i.e., the cache that is closest to the processor). A value of oneis therefore the next layer of cache which may be known as an L2 cache,or even an L1.5 cache in some machines. Values of 2-15 designate thelogical progression of additional cache-latency layers until main memoryis reached, but not including main memory itself. Generally, cachestructures do not go as deep as fifteen layers. Therefore, a value of 15in the IC field 734 and DC control field 736 is interpreted as a specialcase, meaning that a cache miss on instruction fetch or data access,respectively and regardless of cache-latency level, is not recognizedfor the purpose of generating the store of a reporting group. Unlessprohibited by another run-time-instrumentation control, an attempt ismade to store a reporting group representing the sample instructionwhose fetch recognized a miss at a cache-latency level numericallygreater than or equal to the level designated by the value of the ICfield 734. The cache structure and cache-latency level for instructionfetching is model dependent. Model-dependent behavior may ignore thevalue of the IC field 734 and thus not use it as a reason to store areporting group.

The cache-latency-level-override reporting control bit 732 (F bit) isfor non-branch instructions and for branch-prediction controls. When theF bit 732 in the run-time-instrumentation controls is zero, thecache-reporting controls (IC field 734 and DC control field 736) of therun-time-instrumentation controls are checked and used according totheir defined function. The branch-prediction controls (BPxn 722, BPxt724, BPti 726, and BPni 728 bits) of the run-time-instrumentationcontrols are checked and used according to their defined function. Whenthe F bit 732 is one, these same controls are ignored and a reportinggroup is stored unless prohibited by another control.

The data-cache-miss control bit 730 (D bit) indicates if a reportinggroup is to be stored. If the D bit 730 is one, an extra type record mayor may not be placed in the extra section of the reporting group whichcontains model dependent data about the sample instruction.

The MRIC instruction includes branch-prediction (BP) reporting controls(BPxn 722, BPxt 724, BPti 726, and BPni 728). If a BP reporting controlbit in the run-time-instrumentation controls is zero, the correspondingcondition is not checked. If a BP reporting-control bit is one and thecorresponding branch-prediction condition exists, and a reporting groupis stored.

The BPxn bit 722, when one, enables checking of branch-predictioninformation. Thus, if the sample branch is incorrectly predicted to betaken but is not taken, a reporting group is stored.

The BPxt bit 724, when one, enables checking of the branch-predictioninformation. Thus, if the sample branch is incorrectly predicted to benot taken but is taken, a reporting group is stored.

The BPti bit 726, when one, enables checking of the branch-predictioninformation. Thus, if the sample branch is correctly predicted to betaken, and is taken, but the branch target is incorrectly predicted, areporting group is stored.

The BPni bit 728, when one, enables checking of the branch-predictioninformation. Thus, if the sample branch is correctly predicted to not betaken, and is not taken, and the branch target is incorrectly predicted,a reporting group is stored.

The enablement control of transactional-execution-mode records bit 720(X bit) controls the collection of transactional-execution-mode abortrecords. When the X bit 720 in the run-time-instrumentation controls iszero, transactional-execution-mode abort records are not collected. Whenthe X bit 720 is one, transactional-execution mode abort records arecollected and placed in the collection buffer 508 of FIG. 5. If a modeldoes not have a transactional-execution facility installed, the X bit720 is ignored.

The RIEMIT instruction control bit 718 (E bit) controls the execution ofthe RIEMIT instruction. When the E bit 718 in therun-time-instrumentation controls is zero or ignored and treated as zerowhen run-time-instrumentation is enabled, RIEMIT executes ano-operation. When E bit 718 is one, and not otherwise ignored, RIEMITis enabled to execute its defined function.

The J bit 746 when zero, specifies that the branch on condition (BC)instruction is in the other-type branch category, regardless of maskvalue. If the J bit 746 is one, the BC instruction which specifies amask of 15 is in the return-type branch category. When the BCinstruction specifies a mask of 1-14, it is not affected by the J bit746 and is always in the other type branch category. When in thereturn-type branch category, the R bit 716 controls inclusion into thecollection buffer 508 of FIG. 5. When in the other type branch category,the B bit 748 controls inclusion into the collection buffer 508. Theother-type branch category may also be indicated as the transfer-typebranch category.

The instruction address code bit 714 (C bit) controls the enablement ofcall type branches. If the C bit 714 in the run-time-instrumentationcontrols is one and the instruction is a call-type branch, thecollection buffer 508 is updated. If model-dependent detection of bothcall-type and return-type branches is combined, the C bit 714 operateson both types and the R bit 716 is not effective.

The R bit 716 is the enablement control of return-type branches. If theR bit 716 in the run-time-instrumentation controls is one and theinstruction is a return-type branch, then the collection buffer 508 isupdated.

The B bit 748 is the enablement control of branches other than call-typeand return-type branches. If the B bit 748 in therun-time-instrumentation controls is one and the instruction is another-type branch recognized by run-time-instrumentation, then thecollection buffer 508 is updated.

The maximum-address exceeded bit 712 (MAE bit), if set to 1, indicatesthat, one or more reporting groups have been stored that have aninstruction address code (C field) set to one. Once the MAE bit 712 isset to one, continuing execution of run-time-instrumentation does notset it back to zero. Execution of the LRIC instruction or the MRICinstruction which specifies the MAE bit 712 as zero will set the MAE bit712 to zero.

The run-time-instrumentation next (RINEXT) control bit 710 (N bit)controls the enablement of the run-time-instrumentation nextinstruction, which controls the execution of a sample instruction. Whenthe N bit 710 in the run-time-instrumentation controls is zero orignored and treated as zero, RINEXT executes a no-operation. When the Nbit 710 is one, and not otherwise ignored, RINEXT is enabled to executeits defined function.

The mode field 708 (M field) is a 4-bit unsigned integer whose value inthe run-time-instrumentation controls specifies the sampling mode forthe run-time-instrumentation controls. Supported sampling modes, mayinclude sampling based on counting CPU cycles, counting instructions, orbe directed to sample in response to a sample instruction, such asRINEXT.

The reporting group size field 744 (RGS) is a 3-bit unsigned integerwhose value specifies the number of records of a reporting group(R_(RG)). The number of records in a reporting group may vary from tworecords, including a begin/timestamp record and an instruction lastrecord, up to two hundred fifty-six records. In an embodiment, the upperlimit may be model dependent. The number of 16-byte records placed intoa reporting group is 2^((RGs+1)).

The primary-CPU capability suppression control bit 738 (Y bit) and thesecondary-CPU capability suppression control bit 739 (Z bit) arecollectively referred to as the suppression control. Suppression of thestoring of a reporting group means that an attempt to store is notperformed. The suppression control is not effective and no suppressionoccurs when the CPU capability of all CPUs in the configuration is thesame. In a configuration, if the CPU capability of a CPU differs fromthe capability of another CPU, the suppression control is in effect, andat least one CPU is said to be operating at the CPU capability orprimary-CPU capability while at least one other CPU is said to beoperating at the secondary-CPU capability. The primary and secondary CPUcapabilities are different operating speeds. When Y bit 738 and Z bit739 are both zero, suppression does not occur. When Y bit 738 is zeroand Z bit 739 is one, suppression occurs if the CPU, e.g., processor106, is operating at the secondary-CPU capability. When Y bit 738 is oneand Z bit 739 is zero, suppression occurs if the CPU, e.g., processor106, is operating at the primary-CPU capability. When Y bit 738 and Zbit 739 are both one, suppression occurs.

The above fields and bits of FIG. 7 are an example of the placement andnaming of the fields and are provided herein for purposes of clarity. Itwill be understood that in other embodiments the only a subset of thefields may be used, fields may be in any order or position, and/or maybe signified by different names.

When run-time instrumentation is installed and enabled, a number ofevents and data can be captured in collection buffer 508. The collectionbuffer 508 is used to capture a set of records whose contents report onevents recognized by the processor 106 during program execution.Examples are: execution of one or more taken branches,transactional-execution abort events, cache-misses, and an operand of arun-time instrumentation emit instruction. The IC and DC controls fields734 and 736 set a level at which the program would be interested intaking some corrective action to improve instruction or data pre-fetchbehavior. Execution of the RIEMIT instruction collects the value of ageneral register by storing it into the collection buffer 508.Additional data can be collected and/or stored in other buffers, such asan instruction-data buffer (IDB) (not depicted) used to collectmodel-dependent sample-instruction data to construct arun-time-instrumentation instruction record.

Collected run-time-instrumentation information is reported on a samplingbasis. Instructions from the instruction stream are sampled. Theinstruction that is sampled is called the sample instruction. A numberof modes for determining a sample instruction are defined as followswhen run-time instrumentation is enabled. In cycle-count mode, a countis the number of CPU cycles specified in either SF 740 or RSIC 742,whichever is used to provide the count for the current interval. Thecount is adjusted responsive to an event associated with the samplingmode. For example, the count may be decremented when the processor 106is in the operating state. When the count is decremented to thresholdvalue, such as zero, the current instruction is recognized as a sampleinstruction, and the count is reinitialized to the SF 740 value andbegins to be decremented with the next cycle. When execution of thesample instruction completes, reporting is performed, if appropriate.

In instruction-count mode, a count is specified in either SF 740 or RSIC742, whichever is used to provide the count for the current interval.For an instruction which consists of a single unit of operation, thecount is decremented at the completion of the instruction as an eventused to adjust the count. The instruction is a sample instruction whenthe count is decremented to a threshold value, such as zero. For aninstruction which consists of multiple units-of-operation, the count maybe decremented in one of the following ways:

a. For an interruptible instruction, all units of operation throughpartial completion represent one counted unit for which the count isdecremented.b. For an interruptible instruction, all units of operation since themost-recent partial completion through final completion represent onecounted unit for which the count is decremented.c. For an instruction that completes after performing a CPU-determinedsubportion of the processing specified by the parameters of theinstruction, the completion represents one counted unit for which thecount is decremented.d. For an instruction that completes after performing multiple units ofoperation but not in categories a-c above, completion of the last unitof operation represents one counted unit for which the count isdecremented.

An instruction is a sample instruction when the count is decremented tozero for any counted unit of the instruction. When a threshold value isreached, such as zero, the count is reinitialized to the SF 740 valueand begins to count down as described in a-d above. In all cases of thecount modes, reporting, if appropriate, occurs after completion of thelast unit of operation of the sample instruction.

In directed-sampling mode, directed sampling occurs when the N-bit 710is one and the RINEXT instruction is executed successfully. The sampleinstruction is the next, sequential instruction (NSI) after the RINEXTinstruction. If the next, sequential instruction is an execute-typeinstruction, the sample instruction is the target instruction of theexecute-type instruction. Directed sampling may occur when in thecycle-count or instruction-count mode. Count sampling continues inconjunction with directed sampling and any of its resulting actions, andis not otherwise affected, except that if the sample instructiondetermined from count sampling is the same instruction determined bydirected sampling, two reporting groups are not stored.

Whatever the sampling mode is, when a sample instruction is identifiedby execution of the RINEXT instruction, a reporting group is stored.However, the run-time-instrumentation controls Y 738, Z 739, Qs 614, andPs 612 continue to be effective.

Cycle-count and instruction-count sampling each determine an approximateinterval which is subject to an amount of variability based on internalsystem events and exception conditions. The countdown begins whenrun-time instrumentation transitions from disabled to enabled. Directedsampling is subject to a lesser amount of variability, depending on anyevent that can be interposed between completion of RINEXT and the NSI.Of note, an interruption can cause what was thought to be the NSI to nolonger be the NSI.

Sampling, regardless of the mode, identifies a sample instruction. Oncea sample instruction is identified, collection stops upon completion ofexecution of the sample instruction and reporting begins. The variousreporting controls that govern reporting then apply. Collection resumeswhen store of the reporting group is made pending.

When not in the transactional-execution mode, store of a reporting groupbecomes pending upon completion of execution of a sample instruction.When in the transactional-execution mode, upon completion of executionof a sample instruction, store of a reporting group is deferred untilthe transaction ends and then becomes pending. When the store of areporting group is deferred or pending, it may be purged if any of thefollowing interruptions is recognized: 1) program interruption; 2)exigent machine-check interruption; 3) restart interruption; and 4)supervisor-call interruption.

Any pending I/O, external, and repressible machine-check interruptionremains pending until either the reporting group has been stored or therun-time-instrumentation controls determine that a reporting group isnot to be stored.

Each mode may or may not allow a different set of reporting controls.When the sampling mode is either instruction count or cycle count, butdirected sampling is also used, it is possible for the same sampleinstruction to be identified by multiple sampling methods. When thisoccurs, and the reporting controls to be used differ according to thesampling mode, the reporting controls associated with directed samplingapply.

Precise determination of an interval meant to sample a particularinstruction is generally not feasible, due to asynchronous andunsolicited system events that may occur. Instead, the RINEXTinstruction can be used to more-closely designate a sample instruction.

When in cycle-count mode or instruction-count mode, the RINEXTinstruction can be issued in too close a proximity to the sampleinstruction identified from instruction-count or cycle-count sampling.The contents of the associated reporting group are as if the sampleinstruction were identified as the NSI of the RINEXT instruction and notas if a cycle-count or instruction-count identification of the sampleinstruction applied.

Execution of RINEXT may execute as a no-operation if any one or more ofthe following exception conditions is met:

1. Run-time-instrumentation controls are not valid.2. In the problem state, Ps 612 of the current run-time-instrumentationcontrols is zero, indicating that problem-state reporting is notpermitted.3. In the supervisor state, Qs 614 of the currentrun-time-instrumentation controls is zero, indicating thatsupervisor-state reporting is not permitted.4. The N-bit 710 of the current run-time-instrumentation controls iszero, indicating that the RINEXT instruction itself is not permitted.5. Storage is suppressed.6. A field in the current PSW indicates that run-time instrumentation isdisabled.7. A model-dependent threshold would be exceeded. The number of timesRINEXT has been issued in a period of time has exceeded amodel-dependent limit.8. A program-buffer-full condition exists.9. A run-time-instrumentation-halted condition exists.10. The next, sequential instruction is a start interpretive executioninstruction.11. The next, sequential instruction is a supervisor call instruction.

Turning to FIG. 8, an embodiment of collection buffer 508 is generallyshown. As described previously, when run-time instrumentation is enabledduring program execution, run-time-instrumentation data is collectedwithin the processor 106. In an embodiment, the place where data iscollected within the processor 106 is the collection buffer 508, andoptionally an instruction-data buffer. In an embodiment, the collectionbuffer 508 is an internal buffer of the processor 106 that is used tosave the most recent records collected. When a sample trigger point isdetected, the records are copied from the collection buffer 508 into theprogram buffer 522 as part of a reporting group that is written to theprogram buffer 522. In an embodiment, the records are copied from thecollection buffer in a non-destructive manner.

The collection buffer 508 may be referred to as a “hardware collectionbuffer” because the collection buffer 508 is located in the processorand in an embodiment implemented as an array of register pairsrepresenting instruction address 802 and event metadata 804 of a givenevent. In an embodiment, the instruction-data buffer is also implementedby an array of register pairs. An example of an event is a taken branchfor which the register pair may hold the instruction address of thebranch, and the metadata may hold the target of the branch as well asinformation regarding the historic behavior of the branch. In anembodiment, the registers pairs are ordered and updated sequentially asevents occur in the instruction stream. A counter is maintained toindicate the index of the most recently updated entry in the array. Inan embodiment the collection buffer 508 is a circular buffer, and whenthe collection buffer 508 is full, the next event overwrites the firstentry in the array, and sequential updating of the array's registerpairs re-starts on subsequent events. As such, assuming an array CB[0]to CB[N−1] and a counter i indicating the latest updated index, thetrace of events captured would be represented by the sequence CB[i],CB[i−1] . . . CB[1], CB[0], CB[N−1], CB[N−2] . . . CB[i+1]. In anotherembodiment, two pointers are used: a head pointer pointing to the oldestentry in the buffer, and a tail/current pointer pointing to the newestentry in the buffer.

Events that represent a state of the processor 106 at any givenexecution point are captured sequentially in the collection buffer 508.The collection buffer 508 is used to capture a set of records whosecontents report on events recognized by the processor 106 during programexecution (e.g., execution of one or more taken branches,transactional-execution abort events, the operand of a RIEMITinstruction, etc.). In an embodiment the events recognized depend on thecontents of the RICCB shown in FIG. 7. Entries in the embodiment of thecollection buffer 508 shown in FIG. 8 include an event instructionaddress 802 and other relevant event metadata 804. Examples of eventmetadata 804 include, but are not limited to: the instruction address ofa taken branch and its target including some information about thehistoric behavior of the branch; the instruction address of a RIEMITinstruction and a respective register value; and the address of atransaction abort instruction and a respective transaction recoveryentry point.

The embodiment of the collection buffer 508 shown in FIG. 8 is capableof storing up to thirty-two entries (i.e., information about thirty-twoevents), with each instruction address 802 specified by sixty-four bits(e.g., bits 0:63), and event metadata 804 by sixty-four bits (e.g., bits64:127). The size of the collection buffer (R_(CB)) is a model dependentcount, representing a number of records. In the embodiment of thecollection buffer 508 shown in FIG. 8, the byte size of the collectionbuffer is a multiple of the sixteen byte record size. In an embodiment,the size of the collection buffer is a number of records greater than orequal to the difference between the count of the largest reporting group(R_(RG)) of the model and the count of the records in a reporting groupthat are not acquired from the collection buffer (R_(NC)). Thus, in anembodiment, the size of the collection buffer is expressed as:R_(CB)≧(R_(RG)−R_(NC)).

In an embodiment, contents of the collection buffer 508 and theinstruction data buffer (if one is used) are purged or otherwiseaffected by the following events: (1) an interruption; (2) the PSW bitthat turns on and off the run-time instrumentation facility (e.g., bit24) changes from a one to a zero; and (3) when a sample instruction isidentified when the run-time instrumentation facility is in atransactional-execution mode (in this case, further update of thecollection data buffer 508 and instruction-data buffer stops and resumeswhen the transaction ends, at which time, a store of the reporting groupis pending and the collection buffer 508 and instruction-data buffersare purged.

In an embodiment, such as the emulated host computer system shown inFIG. 1B, the collection buffer 508 is implemented using registers and/ormemory. In this embodiment, the optional instruction-data buffer, ifpresent, is also implemented using registers and/or memory.

In embodiments, additional capabilities can affect data collection andmay be viewed as providing additional data-collection points while notsubstantially disturbing the regular instruction-count or cycle-countsampling described previously. These include execution of a RIEMITinstruction, which collects the value of a general register by storingit into the collection buffer 508. In addition, the data-collectioncontrol bits in the run-time instrumentation controls describedpreviously can be used to customize the types of data collected (e.g.,the E, C, R, and B control bits). In this manner, the type of datacollected is programmable.

In an embodiment, an instruction-data buffer is implemented to collectmodel dependent sample instruction data that is used to construct arun-time-instrumentation instruction record. The instruction-data buffercollects data from an instruction in anticipation of being availablewhen the instruction is identified as a sample instruction. In anembodiment, the instruction-data buffer is a hardware buffer/storagelocation in the processor where information about an instruction thatwould become the trigger as a sample point is saved, so that during thelog out process, it can be written out together with data from thecollection buffer 508. Similar to the collection buffer 508 it includesthe instruction address, and meta-data associated with that instruction.The metadata in the instruction-data buffer is often machine dependentand may include, but is not limited to: cache miss related information,and branch prediction related information.

In accordance with embodiments, other data collected may not be from thecollection buffer 508 and not from the instruction-data buffer. Examplesinclude data used to form parts of the following: (1) the first recordof a reporting group: timestamp or begin record; and (2) additionaltypes of records may be created for every reporting group and thus notstored in the collection buffer 508, such records, when present, may beplaced in the extra or machine-dependent section of a reporting group.These records are referred to herein as “system information records.”

FIG. 9 depicts a high-level example of a reporting group 900 stored toprogram buffer 522 at a sample point. The size of a reporting group inrecords is represented by R_(RG), equals 2^((RGs+1)), where RGS is thereporting group size as an exponent. A model-dependent number of records(R_(NC)) copied from a location other than the collection buffer 508 mayor may not be copied non-destructively when used in a reporting group.In the example of FIG. 9, R_(RG)=8, R_(GS)=2, and R_(NC)=4. The examplereporting group 900 shown in FIG. 9 includes a header section 902, abody section 904, an extra records section 906, and a footer section908.

The header section 902 may include a begin record or a timestamp recordto hold status, tracking, and/or timing information. A begin record isstored in the header section 902 for the first reporting group stored ina program buffer (i.e., when the RCA 706 is equal to the ROA 702). In anembodiment, the begin record includes a record type field of “02”, anumber of reporting groups (NRG) field for indicating how many reportinggroups are currently stored in the program buffer, a RGS field toindicate the size of the reporting groups, a stopped (S) field forindicating whether or not the program buffer 522 is full, a halted (H)field for indicting whether the run-time instrumentation is halted, anda time of day (TOD) clock field for indicating when the begin record waswritten. In an embodiment, at least a subset of the fields in the beginrecord are sourced from the RI control block (e.g., RICCB). Anembodiment of the timestamp record has a record type of “03” andincludes a TOD clock field for indicating when the record was stored. Inan embodiment, a timestamp record is stored in the header section 902for each reporting group other than the first reporting group.

The body section 904 of the reporting group may include a variety ofrecords for events and information sampled from collection buffer 508.Events and information may represent, for example, state informationcaptured by an emit instruction, a transactional-execution abort, acall, a return, a branch, and filler.

In an embodiment, an emit record is created and stored in the collectionbuffer 508 upon a successful execution of a RIEMIT instruction. Anembodiment of the emit record includes a record type field of “10”, aninstruction address code field to indicate how the instruction addressbit positions of the current PSW are represented in the emit record, aninstruction address field which varies depending on the addressing mode(e.g., 64, 31 or 24 bit) and contains the instruction address of theRIEMIT instruction or execute type instruction if the RIEMIT was thetarget of an execute type instruction, and an emit data field forstoring the data from the general register specified by the RIEMITinstruction.

In an embodiment, a transactional execution mode abort record is createdand stored in the collection buffer 508 by either an implicit abort orby execution of a transaction abort instruction. An embodiment of theabort record includes a record type field of “11”, an instructionaddress code field to indicate how the instruction address bit positionsof the current PSW are represented in the transactional-execution abortrecord, an instruction address field which varies depending on theaddressing mode (e.g., 64, 31 or 24 bit) and contains the instructionaddress of the aborted instruction or execute type instruction if theaborted instruction was the target of an execute type instruction, and afield for any model dependent data associated with the abort.

In an embodiment, a call record is created by execution of a call typebranch instruction, such as: BRANCH AND SAVE (BASR) when the R2 field isnonzero, BRANCH AND SAVE (BAS), BRANCH RELATIVE AND SAVE LONG, BRANCHRELATIVE AND SAVE, BRANCH AND LINK (BALR) when the R2 field is nonzero,BRANCH AND LINK (BAL), and BRANCH AND SAVE AND SET MODE when the R2field is nonzero. An embodiment of the call record includes a recordtype field of “12”, an instruction address code field to indicate howthe instruction address bit positions of the current PSW are representedin the call record, an instruction address field which varies dependingon the addressing mode (e.g., 64, 31 or 24 bit) and contains the addressof the branch instruction or execute type instruction if the branchinstruction was the target of an execute type instruction, and a wellbehaved field for indicating whether or not the branch was correctlypredicted, and a target address field containing the branch targetaddress (also referred to as the “called location”).

Return records and transfer records may have the same format as the callrecords. In an embodiment, a return record has a record type field of“13” and is created by execution of a return type branch instructionsuch as a BRANCH ON CONDITION (BCR) when the R2 field is nonzero and themask is 15. For the return record, the instruction address fieldcontains the address of the branch instruction or execute typeinstruction if the branch is the target of an execute type instruction,and the target address field contains the return location.

In an embodiment, a transfer record has a record type field of “14” andis created by execution of a return type branch instruction such as: a.BRANCH ON CONDITION (BCR) when the R2 field is nonzero and the mask isin the range 1-14; b. BRANCH ON CONDITION (BC) when the J bit is zero orthe mask is in the range 1-14; c. BRANCH ON COUNT (BCT, BCTR, BCTG,BCTGR); d. BRANCH ON INDEX HIGH (BXH, BXHG); e. BRANCH ON INDEX LOW OREQUAL (BXLE, BXLEG); f. BRANCH RELATIVE ON CONDITION (BRC); g. BRANCHRELATIVE ON CONDITION LONG (BRCL); h. BRANCH RELATIVE ON COUNT (BRCT,BRCTG); i. BRANCH RELATIVE ON COUNT HIGH (BRCTH); j. BRANCH RELATIVE ONINDEX HIGH (BRXH, BRXHG); k. BRANCH RELATIVE ON INDEX LOW OR EQUAL(BRXLE, BRXLG); l. COMPARE AND BRANCH (CRB, CGRB); m. COMPARE AND BRANCHRELATIVE (CRJ, CGRJ); n. COMPARE IMMEDIATE AND BRANCH(CIB, CGIB); o.COMPARE IMMEDIATE AND BRANCH RELATIVE (CIJ, CGU); p. COMPARE LOGICAL ANDBRANCH(CLRB, CLGRB); q. COMPARE LOGICAL AND BRANCH RELATIVE (CLRJ,CLGRJ); r. COMPARE LOGICAL IMMEDIATE AND BRANCH (CLIB, CLGIB); and s.COMPARE LOGICAL IMMEDIATE AND BRANCH RELATIVE (CLIJ, CLGU). The transferrecord is created when the branch is taken. For the transfer record, theinstruction address field contains the address of the branch instructionor execute type instruction if the branch is the target of an executetype instruction, and the target address field contains the returnlocation.

A filler record is used in a reporting group when the number of validrecords in the collection buffer 508 is not sufficient to fill areporting group of the current RGS. An embodiment of a filler recordincludes record type field of “00” to indicate that the record is afiller record and the remaining bytes are undefined.

The extra records section 906, when present, may contain model-dependentrecords. In an embodiment, the format of an extra record is similar tothe filler record except for the record type is set to “01” to indicatethat the record is an extra record and the remaining bytes of the extrarecord may contain model dependent data.

The footer section 908 can include an instruction record containinginformation about execution of a sample instruction. An instructionrecord is created when a reporting group is stored for a sampleinstruction. An embodiment of the instruction record includes a recordtype field of “04”, an instruction address code field to indicate howthe instruction address bit positions of the current PSW are representedin the instruction record, an instruction address field which variesdepending on the addressing mode (e.g., 64, 31 or 24 bit) and containsthe instruction address of the sample instruction or execute typeinstruction if the sample instruction was the target of an execute typeinstruction, and an instruction-data buffer (IDB) field containing anymodel dependent data collected from the IDB.

As described previously, the run-time-instrumentation function is a newfacility that may be used in not only in a laboratory environment, orfor off-line analysis, but also in live software environments withinprograms at runtime, and under program control. Initially, a privilegedstate may set controls of a processor 106 to managerun-time-instrumentation. In an embodiment, the set of controls areoriginally loaded by successful execution of the loadrun-time-instruction control (LRIC) instruction by the privileged state.The flexibility of the run-time-instrumentation facility is enhanced byproviding the ability to turn the run-time instrumentation facility onand off from a lesser-privileged state. In this manner, the datacollected by the run-time instrumentation facility can be targeted toparticular instructions.

In accordance with embodiments, both the RIOFF instruction and the RIONinstruction may be executed by an application executing in alesser-privileged state. If the execution of the RIOFF instruction issuccessful, then the run-time instrumentation is disabled when executionof the RIOFF instruction successfully completes, otherwise, if theexecution of the RIOFF instruction is unsuccessful, then the RIOFFinstruction will have no impact on the status (e.g., enabled ordisabled) of the run-time instrumentation facility. Similarly, if theexecution of the RION instruction is successful, then the run-timeinstrumentation is enabled when execution of the RION instructionsuccessfully completes, otherwise, if the execution of the RIONinstruction is unsuccessful, then the RION instruction will have noimpact on the status (e.g., enabled or disabled) of the run-timeinstrumentation facility.

FIG. 11 depicts an RIOFF instruction in accordance with an embodiment.As shown in FIG. 11, the RIOFF instruction 1100 includes an operationcode 1102 and 1104 (also referred to as “opcode” or “split opcode” inthis particular case). The opcode 1102 and 1104 identifies the RIOFFinstruction 1100 to the processor, such as processor 106 of FIG. 5. FIG.11 depicts one embodiment of the RIOFF instruction, it will beunderstood by those of ordinary skill in the art that the RIOFFinstruction may be formatted differently and/or contain differentoperands and opcodes in other embodiments.

FIG. 12 depicts a process flow of an RIOFF instruction in accordancewith an embodiment. In an embodiment, the process flow of FIG. 12 isexecuted by the instrumentation module 506 of FIG. 5. At block 1202, anRIOFF instruction issued by a lesser-privileged state program (e.g. anapplication 518 executing in the problem state) is fetched (e.g., froman instruction stream). In an embodiment, a bit of the PSW is examined(e.g., bit 15) to determine whether the program is executing in asupervisory state or a lesser privileged state (also referred to hereinas a “problem state”). At block 1204 it is determined if execution ofthe RIOFF instruction is permitted. The run-time-instrumentation S bitin the RICCB (controlled only by LRIC) determines if thelesser-privileged state program is allowed to execute the RIOFFinstruction. In an embodiment, if the run-time-instrumentation S bit inthe current run-time instrumentation controls (e.g., in the RICCB) isset to 1, then the lesser privileged state program is allowed to executethe RIOFF instruction and processing continues at block 1208.Alternatively, if the S bit is set to 0, then the lesser privilegedstate program is not allowed to execute the RIOFF instruction, andprocessing continues at block 1206. At block 1206, the RIOFF instructiondoes not change the prior settings, and the runtime controls and PSWremain at their prior values. In an embodiment, at block 1206, acondition code is set to two to indicate that lesser-privileged stateexecution is not enabled.

At block 1208, it is determined if the validity bit (also referred to asthe V bit) of the current run-time-instrumentation controls (e.g., inthe RICCB) is set to 1. The validity bit indicates the validity of theset of run-time instrumentation controls in the processor, as they werepreviously set by an LRIC instruction. If the current run-timeinstrumentation controls are not valid, (i.e. the previous LRICinstruction was invalid), then processing continues at block 1201. In anembodiment, at block 1210, a condition code is set to three to indicatethat the current run-time instrumentation controls are not valid.

If the validity bit is set to 1, indicating that therun-time-instrumentation controls are valid, then processing continuesat block 1212, where the decrementing of the current run-time RSIC issupressed and the value preserved in anticipation of a subsequent RIONinstruction. Processing continues at block 1214, where the RI bit in thePSW (e.g., bit 24) is set to zero. In an embodiment, if bit 24 of thePSW is already zero, then execution of RIOFF completes and a conditioncode is set to zero. In an embodiment, an EXTRACT PSW instruction isexecuted to determine a current value of PSW bit 24.

FIG. 13 depicts a RION instruction in accordance with an embodiment. Asshown in FIG. 13, the RION instruction 1300 includes an operation code1302 and 1304 (also referred to as “opcode” or “split opcode” in thisparticular case). The opcode 1302 and 1304 identifies the RIONinstruction 1300 to the processor, such as processor 106 of FIG. 5. FIG.13 depicts one embodiment of the RION instruction, it will be understoodby those of ordinary skill in the art that the RION instruction may beformatted differently and/or contain different operands and opcodes inother embodiments.

FIG. 14 depicts a process flow of an RION instruction in accordance withan embodiment. In an embodiment, the process flow of FIG. 14 is executedby the instrumentation module 506 of FIG. 5. At block 1402, an RIONinstruction issued by a lesser-privileged state program (e.g. anapplication 518 executing in the problem state) is fetched (e.g., froman instruction stream). In an embodiment, a bit of the PSW is examined(e.g., bit 15) to determine whether the program is executing in asupervisory state or a lesser privileged state (also referred to hereinas a “problem state”). At block 1404 it is determined if execution ofthe RION instruction is permitted. The run-time-instrumentation S bit(controlled only by LRIC) determines if the lesser-privileged stateprogram is allowed to execute the RION instruction. In an embodiment, ifthe run-time-instrumentation S bit in the current run-timeinstrumentation controls (e.g., in the RICCB) is set to 1, then thelesser privileged state program is allowed to execute the RIONinstruction and processing continues at block 1408. Alternatively, ifthe S bit is set to 0, then the lesser privileged state program is notallowed to execute the RION instruction, and processing continues atblock 1406. In an embodiment, at block 1406, the RION instruction doesnot change the prior settings, and the runtime controls and PSW remainat their prior values. In an embodiment, at block 1406, a condition codeis set to two to indicate that lesser-privileged state execution is notenabled.

At block 1408, it is determined if the validity bit (also referred to asthe V bit) of the current run-time-instrumentation controls (e.g., inthe RICCB) is set to 1. The validity bit indicates the validity of theset of run-time instrumentation controls in the processor, as they werepreviously set by an LRIC instruction. If the current run-timeinstrumentation controls are not valid, (i.e. the previous LRICinstruction was invalid), then processing continues at block 1410. In anembodiment, at block 1410, a condition code is set to three to indicatethat the current run-time instrumentation controls are not valid.

If the validity bit is set to 1, indicating that therun-time-instrumentation controls are valid, then processing continuesat block 1412, where the contents of the collection buffer, and theinstruction-data buffer if present, are purged. In an embodiment, thebuffers are purged at block 1412 only when the RI bit in the PSW waspreviously set to zero. Processing continues at block 1414, where the RIbit in the PSW (e.g., bit 24) is set to one. In an embodiment, if bit 24of the PSW is already one, then execution of the RION instructioncompletes and a condition code is set to zero. In an embodiment, anEXTRACT PSW instruction is executed to determine a current value of PSWbit 24.

In an embodiment, if the run-time instrumentation facility is executingin sampling modes 0 or 1 (as determined, for example by the RCCB), thena non-zero RSIC is used to continue the remainder of the interval. Ifthe RSIC is zero, then a new sampling interval is initialized to thevalue of the scaling factor and the A bit in the RICCB is set to one.

As described above, embodiments can be embodied in the form ofcomputer-implemented processes and apparatuses for practicing thoseprocesses. An embodiment may include a computer program product 1500 asdepicted in FIG. 15 on a computer readable/usable medium 1502 withcomputer program code logic 1504 containing instructions embodied intangible media as an article of manufacture. Exemplary articles ofmanufacture for computer readable/usable medium 1502 may include floppydiskettes, CD-ROMs, hard drives, universal serial bus (USB) flashdrives, or any other computer-readable storage medium, wherein, when thecomputer program code logic 1504 is loaded into and executed by acomputer, the computer becomes an apparatus for practicing theinvention. Embodiments include computer program code logic 1504, forexample, whether stored in a storage medium, loaded into and/or executedby a computer, or transmitted over some transmission medium, such asover electrical wiring or cabling, through fiber optics, or viaelectromagnetic radiation, wherein, when the computer program code logic1504 is loaded into and executed by a computer, the computer becomes anapparatus for practicing the invention. When implemented on ageneral-purpose microprocessor, the computer program code logic 1504segments configure the microprocessor to create specific logic circuits.

Technical effects and benefits include the ability to limit sampling bya run-time instrumentation facility to a subset of the execution traceof an application. This may lead to a more focused data set from theinstrumentation. In addition, by limiting the sampling to a subset ofthe execution trace, the cost of having to manage, buffer, and reducethe instrumentation data is decreased.

The terminology used herein is for the purpose of describing particularembodiments only and is not intended to be limiting of the invention. Asused herein, the singular forms “a”, “an” and “the” are intended toinclude the plural forms as well, unless the context clearly indicatesotherwise. It will be further understood that the terms “comprises”and/or “comprising,” when used in this specification, specify thepresence of stated features, integers, steps, operations, elements,and/or components, but do not preclude the presence or addition of oneor more other features, integers, steps, operations, elements,components, and/or groups thereof.

The corresponding structures, materials, acts, and equivalents of allmeans or step plus function elements in the claims below are intended toinclude any structure, material, or act for performing the function incombination with other claimed elements as specifically claimed. Thedescription of the present invention has been presented for purposes ofillustration and description, but is not intended to be exhaustive orlimited to the invention in the form disclosed. Many modifications andvariations will be apparent to those of ordinary skill in the artwithout departing from the scope and spirit of the invention. Theembodiment was chosen and described in order to best explain theprinciples of the invention and the practical application, and to enableothers of ordinary skill in the art to understand the invention forvarious embodiments with various modifications as are suited to theparticular use contemplated.

As will be appreciated by one skilled in the art, aspects of the presentinvention may be embodied as a system, method or computer programproduct. Accordingly, aspects of the present invention may take the formof an entirely hardware embodiment, an entirely software embodiment(including firmware, resident software, micro-code, etc.) or anembodiment combining software and hardware aspects that may allgenerally be referred to herein as a “circuit,” “module” or “system.”Furthermore, aspects of the present invention may take the form of acomputer program product embodied in one or more computer readablemedium(s) having computer readable program code embodied thereon.

Any combination of one or more computer readable medium(s) may beutilized. The computer readable medium may be a computer readable signalmedium or a computer readable storage medium. A computer readablestorage medium may be, for example, but not limited to, an electronic,magnetic, optical, electromagnetic, infrared, or semiconductor system,apparatus, or device, or any suitable combination of the foregoing. Morespecific examples (a non-exhaustive list) of the computer readablestorage medium would include the following: an electrical connectionhaving one or more wires, a portable computer diskette, a hard disk, arandom access memory (RAM), a read-only memory (ROM), an erasableprogrammable read-only memory (EPROM or Flash memory), an optical fiber,a portable compact disc read-only memory (CD-ROM), an optical storagedevice, a magnetic storage device, or any suitable combination of theforegoing. In the context of this document, a computer readable storagemedium may be any tangible medium that can contain, or store a programfor use by or in connection with an instruction execution system,apparatus, or device.

A computer readable signal medium may include a propagated data signalwith computer readable program code embodied therein, for example, inbaseband or as part of a carrier wave. Such a propagated signal may takeany of a variety of forms, including, but not limited to,electro-magnetic, optical, or any suitable combination thereof. Acomputer readable signal medium may be any computer readable medium thatis not a computer readable storage medium and that can communicate,propagate, or transport a program for use by or in connection with aninstruction execution system, apparatus, or device.

Program code embodied on a computer readable medium may be transmittedusing any appropriate medium, including but not limited to wireless,wireline, optical fiber cable, RF, etc., or any suitable combination ofthe foregoing.

Computer program code for carrying out operations for aspects of thepresent invention may be written in any combination of one or moreprogramming languages, including an object oriented programming languagesuch as Java, Smalltalk, C++ or the like and conventional proceduralprogramming languages, such as the “C” programming language or similarprogramming languages. The program code may execute entirely on theuser's computer, partly on the user's computer, as a stand-alonesoftware package, partly on the user's computer and partly on a remotecomputer or entirely on the remote computer or server. In the latterscenario, the remote computer may be connected to the user's computerthrough any type of network, including a local area network (LAN) or awide area network (WAN), or the connection may be made to an externalcomputer (for example, through the Internet using an Internet ServiceProvider).

Aspects of the present invention are described above with reference toflowchart illustrations and/or schematic diagrams of methods, apparatus(systems) and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer program instructions. These computer program instructions maybe provided to a processor of a general purpose computer, specialpurpose computer, or other programmable data processing apparatus toproduce a machine, such that the instructions, which execute via theprocessor of the computer or other programmable data processingapparatus, create means for implementing the functions/acts specified inthe flowchart and/or block diagram block or blocks.

These computer program instructions may also be stored in a computerreadable medium that can direct a computer, other programmable dataprocessing apparatus, or other devices to function in a particularmanner, such that the instructions stored in the computer readablemedium produce an article of manufacture including instructions whichimplement the function/act specified in the flowchart and/or blockdiagram block or blocks.

The computer program instructions may also be loaded onto a computer,other programmable data processing apparatus, or other devices to causea series of operational steps to be performed on the computer, otherprogrammable apparatus or other devices to produce a computerimplemented process such that the instructions which execute on thecomputer or other programmable apparatus provide processes forimplementing the functions/acts specified in the flowchart and/or blockdiagram block or blocks.

As described above, embodiments can be embodied in the form ofcomputer-implemented processes and apparatuses for practicing thoseprocesses. In embodiments, the invention is embodied in computer programcode executed by one or more network elements. Embodiments include acomputer program product on a computer usable medium with computerprogram code logic containing instructions embodied in tangible media asan article of manufacture. Exemplary articles of manufacture forcomputer usable medium may include floppy diskettes, CD-ROMs, harddrives, universal serial bus (USB) flash drives, or any othercomputer-readable storage medium, wherein, when the computer programcode logic is loaded into and executed by a computer, the computerbecomes an apparatus for practicing the invention. Embodiments includecomputer program code logic, for example, whether stored in a storagemedium, loaded into and/or executed by a computer, or transmitted oversome transmission medium, such as over electrical wiring or cabling,through fiber optics, or via electromagnetic radiation, wherein, whenthe computer program code logic is loaded into and executed by acomputer, the computer becomes an apparatus for practicing theinvention. When implemented on a general-purpose microprocessor, thecomputer program code logic segments configure the microprocessor tocreate specific logic circuits.

The flowchart and block diagrams in the Figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing the specified logical function(s). It should also be notedthat, in some alternative implementations, the functions noted in theblock may occur out of the order noted in the figures. For example, twoblocks shown in succession may, in fact, be executed substantiallyconcurrently, or the blocks may sometimes be executed in the reverseorder, depending upon the functionality involved. It will also be notedthat each block of the block diagrams and/or flowchart illustration, andcombinations of blocks in the block diagrams and/or flowchartillustration, can be implemented by special purpose hardware-basedsystems that perform the specified functions or acts, or combinations ofspecial purpose hardware and computer instructions.

What is claimed is:
 1. A method for enabling and disabling execution of a run-time instrumentation facility on a processor, the method comprising: fetching, by a processor, an instruction for execution by the processor in a lesser privileged state, the instruction one of a run-time instrumentation facility off (RIOFF) instruction and a run-time instrumentation facility on (RION) instruction; based on determining, by the processor, that the run-time instrumentation facility permits execution of the instruction in the lesser-privileged state and that controls associated with the run-time instrumentation facility are valid, executing the instruction, the executing comprising any one of: disabling the run-time instrumentation facility based on the instruction being the RIOFF instruction, the disabling including updating a bit in a program status word (PSW) of the processor to indicate that run-time instrumentation data should not be captured by the processor; and enabling the run-time instrumentation facility based on the instruction being the RION instruction, the enabling including updating the bit in the PSW to indicate that run-time instrumentation data should be captured by the processor.
 2. The method of claim 1, further comprising: fetching, by the processor, a run-time instrumentation control block (RICCB) that includes a problem state execution control bit previously set to a value by a program executing in a privileged state, wherein the determining that the run-time instrumentation facility permits execution of the instruction in the lesser-privileged state is based on the value of the problem state execution control bit.
 3. The method of claim 1, further comprising: fetching, by the processor, a run-time instrumentation control block (RICCB) that includes a validity bit previously set to a value by a program executing in a privileged state, wherein the determining that controls associated with the run-time instrumentation facility are valid is based on the value of the validity bit.
 4. The method of claim 1, further comprising, based on the enabling: capturing, by the processor, the run-time instrumentation data based on an instruction stream of instructions of an application program executing on the processor, the capturing comprising storing the run-time instrumentation data in a collection buffer of the processor; detecting, by the processor, a run-time instrumentation sample point trigger; and copying contents of the collection buffer into a program buffer as a reporting group based on the detecting the run-time instrumentation sample point trigger, the program buffer located in main storage in an address space that is accessible by the application program.
 5. The method of claim 4, further comprising capturing, in the collection buffer, instruction addresses and metadata corresponding to events detected during the executing of the instruction stream.
 6. The method of claim 4, wherein the reporting group includes a predetermined number of one or more instrumentation records comprising contents of the collection buffer and system information records.
 7. The method of claim 4, wherein the copying includes copying the reporting group into the program buffer starting at a current address of the program buffer, the program buffer stored at a program buffer origin address specified by an instruction accessible control block that also specifies an address of a last byte in the program buffer and the current address in the program buffer.
 8. The method of claim 1, further comprising: saving a remaining sample interval count (RSIC) field based on the disabling; fetching, by the processor, a RION instruction; and restoring the RSIC field. 